var numg = 1;
var numf = 1;
var nump = 1;
document.getElementById('btnDelg').disabled=true;
document.getElementById('btnDelf').disabled=true;
document.getElementById('btnDelp').disabled=true;

function addg() {

    var newNum    = new Number(numg + 1);        // the numeric ID of the new input field being added

    // create the new element via clone(), and manipulate it's ID using newNum value
    
    var newselect = document.createElement("select");
    newselect.name='gtipo'+newNum;
    newselect.id='gtipo'+newNum;
    newselect.setAttribute("required", "true");
    newselect.setAttribute("style", "width:155px");
    newselect.innerHTML='<option value="" disabled="disabled" selected="selected">| Elije la Fuente |</option><option value="1">Ente Público</option><option value="2">Ente Privado</option>';
    // manipulate the name/id values of the input inside the new element
    var newinput = document.createElement("input");
    newinput.type='text';
    newinput.name= 'gdescriptcion'+newNum;
    newinput.id= 'gdescriptcion'+newNum;
    newinput.setAttribute("class", "span9");
    newinput.setAttribute("required", "true");
    newinput.setAttribute("style", "margin-left:13px");
    newinput.placeholder='ingrese una descipción';
    // insert the new element after the last "duplicatable" input field
    document.getElementById('gdescriptcion'+numg).parentNode.appendChild(newselect);
    document.getElementById(newselect.id).parentNode.appendChild(newinput);

    // enable the "remove" button
    document.getElementById('btnDelg').disabled=false;
    numg++;
    // business rule: you can only add 5 names
   
};

function delg() {

    document.getElementById('gtipo' + numg).remove();        // remove the last element
    document.getElementById('gdescriptcion' + numg).remove(); 
    numg--;
    // enable the "add" button


    // if only one element remains, disable the "remove" button
    if (numg-1 == 0)
        document.getElementById('btnDelg').disabled=true;
};

function addf() {

    var newNum    = new Number(numf + 1);        // the numeric ID of the new input field being added

    // create the new element via clone(), and manipulate it's ID using newNum value
    
    var newselect = document.createElement("select");
    newselect.name='ftipo'+newNum;
    newselect.id='ftipo'+newNum;
    newselect.setAttribute("required", "true");
    newselect.setAttribute("style", "width:155px");
    newselect.innerHTML='<option value="" disabled="disabled" selected="selected">| Elije la Fuente |</option><option value="1">Ente Público</option><option value="2">Ente Privado</option>';
    // manipulate the name/id values of the input inside the new element
    var newinput = document.createElement("input");
    newinput.type='text';
    newinput.name= 'fdescriptcion'+newNum;
    newinput.id= 'fdescriptcion'+newNum;
    newinput.setAttribute("class", "span9");
    newinput.setAttribute("required", "true");
    newinput.setAttribute("style", "margin-left:13px");
    newinput.style="margin-left:10px";
    newinput.placeholder='ingrese una descipción';
    // insert the new element after the last "duplicatable" input field
    document.getElementById('fdescriptcion'+numf).parentNode.appendChild(newselect);
    document.getElementById(newselect.id).parentNode.appendChild(newinput);

    // enable the "remove" button
    document.getElementById('btnDelf').disabled=false;
    numf++;
    // business rule: you can only add 5 names
   
};

function delf() {

    document.getElementById('ftipo' + numf).remove();        // remove the last element
    document.getElementById('fdescriptcion' + numf).remove(); 
    numf--;
    // enable the "add" button


    // if only one element remains, disable the "remove" button
    if (numf-1 == 0)
        document.getElementById('btnDelf').disabled=true;
};

function addp() {

    var newNum    = new Number(nump + 1);        // the numeric ID of the new input field being added

    // create the new element via clone(), and manipulate it's ID using newNum value
    var newinput0 = document.createElement("input");
    newinput0.type='number';
    newinput0.name= 'cantidad'+newNum;
    newinput0.id= 'cantidad'+newNum;
    newinput0.setAttribute("class", "span2");
    newinput0.setAttribute("required", "true");
    newinput0.placeholder='Cantidad';
    // manipulate the name/id values of the input inside the new element
    var newinput = document.createElement("input");
    newinput.type='text';
    newinput.name= 'grado'+newNum;
    newinput.id= 'grado'+newNum;
    newinput.setAttribute("class", "span10");
    newinput.setAttribute("required", "true");
    newinput.setAttribute("style", "margin-left:13px");
    newinput.style="margin-left:10px";
    newinput.placeholder='Tipo/Grado Academico';
    // insert the new element after the last "duplicatable" input field
    document.getElementById('grado'+nump).parentNode.appendChild(newinput0);
    document.getElementById(newinput0.id).parentNode.appendChild(newinput);

    // enable the "remove" button
    document.getElementById('btnDelp').disabled=false;
    nump++;
    // business rule: you can only add 5 names
   
};

function delp() {

    document.getElementById('cantidad' + nump).remove();        // remove the last element
    document.getElementById('grado' + nump).remove(); 
    nump--;
    // enable the "add" button


    // if only one element remains, disable the "remove" button
    if (nump-1 == 0)
        document.getElementById('btnDelp').disabled=true;
};

function boxclick(id, tipo){
    var cbox = document.getElementById(id);
    if(cbox.checked){
        var newinput2=document.createElement("spam");
        newinput2.id= 'r2-'+tipo+'-'+id;
        newinput2.setAttribute("class", "span12");
        if(tipo==1){
            var aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='Si';
            var aux2=document.createElement("input");
            aux2.value=1;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
            aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='No';
            aux2=document.createElement("input");
            aux2.value=0;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
        }
        if(tipo==2){
            var aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='Excelente';
            var aux2=document.createElement("input");
            aux2.value=4;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
            aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='Muy buena';
            aux2=document.createElement("input");
            aux2.value=3;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
            aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='Buena';
            aux2=document.createElement("input");
            aux2.value=2;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
            aux=document.createElement("label");
            aux.setAttribute("class", "radio");
            aux.innerHTML='Mala';
            aux2=document.createElement("input");
            aux2.value=1;
            aux2.type='radio';
            aux2.id='r-'+id;
            aux2.name='r-'+id;
            aux.appendChild(aux2);
            newinput2.appendChild(aux);
        }
        if(tipo==3){
            var aux=document.createElement("input");
            aux.type='number';
            aux.placeholder='Cantidad';
            aux.id='r-'+id;
            aux.name='r-'+id;
            aux.setAttribute("class", "span2");
            newinput2.appendChild(aux);
        }
        if(tipo==4){
            var aux=document.createElement("input");
            aux.type='number';
            aux.id='r-'+id;
            aux.name='r-'+id;
            aux.placeholder='Porcentaje';
            aux.setAttribute("class", "span2");
            newinput2.appendChild(aux);
        }
        var newinput1 = document.createElement("input");
        newinput1.type='text';
        newinput1.id= 'r1-'+id;
        newinput1.name= 'r1-'+id;
        newinput1.placeholder='Descipción';
        newinput1.setAttribute("class", "span10");
        document.getElementById(id).parentNode.appendChild(newinput2);
        document.getElementById(id).parentNode.appendChild(newinput1);
    }else{
        document.getElementById('r1-'+id).remove();
        document.getElementById('r2-'+tipo+'-'+id).remove();
    }
};

function boxclick2(id, tipo){
    var cbox = document.getElementById(id);
    if(cbox.checked){
        $('#r1-'+id).show();
        $('#r2-'+tipo+'-'+id).show();
    }else{
        $('#r1-'+id).hide();
        $('#r2-'+tipo+'-'+id).hide();
    }
};